We are migrating the bug tracker to github Issues. This is now the preferred way to report NASM bugs.

Self-registration is disabled due to spam issue (mail gorcunov@gmail.com or hpa@zytor.com to create an account)

Bug 3392963 - Listing of mmacro using incbin lists the wrong offsets (behind the data) per <bin ...> except for the last <bin ...>
Summary: Listing of mmacro using incbin lists the wrong offsets (behind the data) per ...
Status: OPEN
Alias: None
Product: NASM
Classification: Unclassified
Component: Assembler (show other bugs)
Version: 3.01 (development)
Hardware: All All
: Medium annoyance
Assignee: nobody
URL:
Depends on:
Blocks:
 
Reported: 2025-10-09 01:46 PDT by E. C. Masloch
Modified: 2025-10-09 01:46 PDT (History)
4 users (show)

Obtained from: Built from git using configure
Generated by: Human
Bug category: Incorrect listing or map file output, Unexpected or confusing behavior
Observed for: Production code
Regression: No
Regression since:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description E. C. Masloch 2025-10-09 01:46:03 PDT
I noticed this error in assembling my debugger's extension library, https://hg.pushbx.org/ecm/ldebug/file/ecbec1e71753/source/eld/extlib.asm#l1144

Following test case based on that source text shows the unexpected behaviour:

test$ cat test.asm

%define INCBINLIST db ""

        %imacro libeld 1-2.nolist
%strcat %%label "lib_", %1
%deftok %%token %%label
 %strcat %%filename %1,".eld"
%xdefine INCBINLIST INCBINLIST, {align 16, db 0}, %%token:, incbin %%filename
        dd %%token
        %endmacro

        %imacro dump_incbin 1-*.nolist
%rep %0
        %1
 %rotate 1
%endrep
        %endmacro

        section table vstart=0
libeld "a"
libeld "b"
libeld "c"

        section lib vstart=0
dump_incbin INCBINLIST
test$ dd if=/dev/zero bs=1 of=a.eld count=512
512+0 records in
512+0 records out
512 bytes copied, 0.000743326 s, 689 kB/s
test$ dd if=/dev/zero bs=1 of=b.eld count=1024
1024+0 records in
1024+0 records out
1024 bytes (1.0 kB, 1.0 KiB) copied, 0.00126436 s, 810 kB/s
test$ dd if=/dev/zero bs=1 of=c.eld count=2048
2048+0 records in
2048+0 records out
2048 bytes (2.0 kB, 2.0 KiB) copied, 0.0024213 s, 846 kB/s
test$ nasm -v
NASM version 2.16.02rc2 compiled on Oct 12 2023
test$ nasm test.asm -l /dev/stderr
     1
     2                                  %define INCBINLIST db ""
     3
     4                                          %imacro libeld 1-2.nolist
     5                                  %strcat %%label "lib_", %1
     6                                  %deftok %%token %%label
     7                                   %strcat %%filename %1,".eld"
     8                                  %xdefine INCBINLIST INCBINLIST, {align 16, db 0}, %%token:, incbin %%filename
     9                                          dd %%token
    10                                          %endmacro
    11
    12                                          %imacro dump_incbin 1-*.nolist
    13                                  %rep %0
    14                                          %1
    15                                   %rotate 1
    16                                  %endrep
    17                                          %endmacro
    18
    19                                          section table vstart=0
    20 00000000 [00000000]              libeld "a"
    21 00000004 [00020000]              libeld "b"
    22 00000008 [00060000]              libeld "c"
    23
    24                                          section lib vstart=0
    25 00000200 <bin 200h>-             dump_incbin INCBINLIST
    25 00000600 <bin 400h>-
    25 00000600 <bin 800h>
test$ ~/proj/nasmtest/rc/nasm -v
NASM version 3.01rc2 compiled on Oct  6 2025
test$ ~/proj/nasmtest/rc/nasm test.asm -l /dev/stderr
     1
     2                                  %define INCBINLIST db ""
     3
     4                                          %imacro libeld 1-2.nolist
     5                                  %strcat %%label "lib_", %1
     6                                  %deftok %%token %%label
     7                                   %strcat %%filename %1,".eld"
     8                                  %xdefine INCBINLIST INCBINLIST, {align 16, db 0}, %%token:, incbin %%filename
     9                                          dd %%token
    10                                          %endmacro
    11
    12                                          %imacro dump_incbin 1-*.nolist
    13                                  %rep %0
    14                                          %1
    15                                   %rotate 1
    16                                  %endrep
    17                                          %endmacro
    18
    19                                          section table vstart=0
    20 00000000 [00000000]              libeld "a"
    21 00000004 [00020000]              libeld "b"
    22 00000008 [00060000]              libeld "c"
    23
    24                                          section lib vstart=0
    25 00000200 <bin 200h>-             dump_incbin INCBINLIST
    25 00000600 <bin 400h>-
    25 00000600 <bin 800h>
test$


I expect the listing offsets for dump_incbin to be 0000, 0200, 0600 instead of the 0200, 0600, 0600 that we get.